package com.qf.fmall2202.vo;

import java.util.HashMap;
import java.util.Map;

public class ResultVo extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResultVo() {
        put("code", 10000);
        put("msg", "success");
    }

    public ResultVo(int code, String msg, Object data) {
        put("code", code);
        put("msg", msg);
        put("data", data);
    }

    public static ResultVo error() {
        return error(10001, "未知异常，请联系管理员");
    }

    public static ResultVo error(String msg) {
        return error(10001, msg);
    }

    public static ResultVo error(int code, String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", code);
        resultVo.put("msg", msg);
        return resultVo;
    }

    public static ResultVo error(String msg, Object data) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", 10001);
        resultVo.put("msg", msg);
        resultVo.put("data", data);
        return resultVo;
    }

    public static ResultVo ok(String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("msg", msg);
        return resultVo;
    }

    public static ResultVo ok(String msg, Object data) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", 10000);
        resultVo.put("msg", msg);
        resultVo.put("data", data);
        return resultVo;
    }

    public static ResultVo ok(Map<String, Object> map) {
        ResultVo resultVo = new ResultVo();
        resultVo.putAll(map);
        return resultVo;
    }

    public static ResultVo ok() {
        return new ResultVo();
    }

    @Override
    public ResultVo put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
